<template>
  	<el-dialog v-model="dialogPromoteVisible" title="赋权操作" center width="30%">
		<el-radio-group v-model="radio" class="ml-4">
			<el-radio label="产品管理员" size="large">产品管理员</el-radio>
			<el-radio label="用户管理员" size="large">用户管理员</el-radio>
			<el-radio label="消息管理员" size="large">消息管理员</el-radio>
		</el-radio-group>
		<template #footer>
			<span class="dialog-footer">
				<el-button type="primary" @click="yes">
					确定
				</el-button>
			</span>
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import {changeIdentityToAdmin} from '@/api/userinfo/index'
import type {changeIdentityToAdminForm} from '@/api/userinfo/type'
import { ElMessage } from "element-plus"
const dialogPromoteVisible = ref<boolean>(false)
const radio = ref()
//确定
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const yes = async()=>{
    let data:changeIdentityToAdminForm = {
        id:ids.value,
        identity:radio.value
    }
   const res = await changeIdentityToAdmin(data)
   if(res.status == 0){
    ElMessage({
        type:'success',
        message:'赋权成功'
    })
     emit('success')
    dialogPromoteVisible.value = false
   }else{
    ElMessage({
        type:'error',
        message:'赋权失败'
    })
   }

}
const ids = ref(0)
const open = (id:number)=>{
    ids.value = id
    dialogPromoteVisible.value = true
}
defineExpose({
    open
})
</script>

<style lang="scss" scoped>
	.el-radio-group {
		display: flex;
		justify-content: center;
	}
</style>
